<?php 
//获取当前视图下的当前url
$_lang = Mage::getModel('core/store')->load(8);
$this_url = $_lang->getCurrentUrl();

//url重定向
$this->_redirect('customer/account/login');
$this->_redirectUrl('http://contus.com');
$this->getResponse()->setRedirect($this_url);
Mage::app()->getResponse()->setRedirect(Mage::getUrl('customer/account/login'));
Mage::app()->getResponse()->setRedirect($url)->sendResponse();
Mage::app()->getFrontController()->getResponse()->setRedirect($url)->sendResponse();

//获取当前视图ID
Mage::app()->getStore()->getStoreId();

//获取当前页面分类
Mage::registry('current_category');

//价格格式化
number_format($number, 2, '.', ''); 

//获取用户
Mage::getSingleton('customer/session')->getCustomer();

//获取用户组名称
Mage::getSingleton('customer/group')->load($customer_group)->getData('customer_group_code');

//set session
Mage::getSingleton('core/session');
Mage::getSingleton('customer/session');
Mage::getSingleton('admin/session');
Mage::getSingleton('checkout/session');

//获取当前时间
Mage::getModel('core/date' )->timestamp(time());

//getRequest
Mage::app()->getRequest()->getParam('id'); 
$this->getRequest()->getParam('id');
  
//getModel
Mage::getModel('sales/order');

//helper
$helper = Mage::helper('addtocart');

//print sql
$collection=Mage::getResourceModel('reports/product_collection');
$query=$collection->getSelectSql(true);
echo $query;
$collection=Mage::getResourceModel('reports/product_collection');
$collection->printlogquery(true);

//join left
$collection->getSelect()->join('sales_flat_order', 'main_table.entity_id=sales_flat_order.entity_id', array('customer_firstname', 'sender_name')
)->join('sales_flat_shipment_track', 'main_table.entity_id=sales_flat_shipment_track.order_id', array('track_number', 'track_number'));

$collection->getSelect()->joinLeft('customer_entity_varchar', '`customer_entity_varchar`.attribute_id=201 AND `customer_entity_varchar`.entity_id = `main_table`.`entity_id`', array('tcode'  => 'customer_entity_varchar.value'));
$collection->groupByAttribute('entity_id');
$collection->getSelect()->group('entity_id');  
    
    
//customer
if(Mage::getSingleton('customer/session')->isLoggedIn()) {
     $customerData = Mage::getSingleton('customer/session')->getCustomer();
      echo $customerData->getId();
}
 
 //消息
 Mage::getSingleton('core/session')->addSuccess('Your request has been sent！');
 Mage::getSingleton('core/session')->addError('Unable to send!');
 Mage::getSingleton('core/session')->addNotice('Your request has been sent!!!!');
 
// 消息 Action()
$this->loadLayout();
//需要添加如下代码：
$this->_initLayoutMessages('core/session');
$this->renderLayout();
   
echo $this->getMessagesBlock()->getGroupedHtml();
echo $this->getMessagesBlock()->toHtml();

//订单状态
$order->addStatusToHistory('itback', Mage::helper('sales')->__('申请退货.'));							
$order->setState(Mage_Sales_Model_Order::STATE_CANCELED, 'itback', Mage::helper('sales')->__('订单状态已更新为退货.'), true);

//开发票
if($order->canInvoice()) {          
    $invoiceId = Mage::getModel('sales/order_invoice_api')
            ->create($order->getIncrementId(), $itemsarray ,'your_comment' ,1,1);
}

//订单号
Mage::getModel('sales/order')->loadByIncrementId($orderincrmentid);


//$payment_method = $odl_order->getPayment()->getMethodInstance()->getCode();

//ControllerName ActionName ModuleName

$this->getRequest()->getControllerName();
$this->getRequest()->getActionName();  
$this->getRequest()->getModuleName();  
var_dump(getRequest());

//form key
Mage::getSingleton('core/session')->getFormKey();

//查询符合条件的第一条用户数据
$customer = Mage::getResourceModel('customer/customer_collection')
            ->addAttributeToFilter('openid', $openid)
            ->getFirstItem();

//库存
$stock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product);
$stock->setQty($qty);
$stock->setIsInStock($stock_status);
$stock->setStockStatus($stock_status);
$stock->save();


//用户登陆

Mage::getSingleton('customer/session')->setCustomerAsLoggedIn($customer)->renewSession();
$session = Mage::getSingleton('customer/session');
$session->login($customer->getEmail(), admin123456);


//订单获取商品总数
$orderId = 5;  //PASS YOUR ORDER ID HERE
$order = $this->orderFactory->create()->load($orderId);
$orderItems = $order->getAllItems();
$total_qty = 0;
foreach ($orderItems as $item)
{
    $total_qty = $total_qty + $item->getQtyOrdered();
}
return $total_qty;
//订单获取商品总数 使用对象管理器
$order_id = 5;  //PASS YOUR ORDER ID HERE
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$order = $objectManager->create('Magento\Sales\Model\Order')->load($order_id);
$orderItems = $order->getAllItems();
$total_qty = 0;
foreach ($orderItems as $item)
{
   $total_qty = $total_qty + $item->getQtyOrdered();
}
 
echo $total_qty;
